home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17321 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  40 lines

  1. Path: news1.intercall.com!usenet
  2. From: engevar@intercall.com (Steven Ovits)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual function does not make any sense unless it is pure.
  5. Date: Mon, 15 Apr 1996 12:29:05 GMT
  6. Organization: Intercall Inc.
  7. Message-ID: <4kt62v$9a4@news1.intercall.com>
  8. References: <4kkhbc$nj4@brahms.udel.edu> <316E9AC3.1124@zurich.ibm.com>
  9. NNTP-Posting-Host: 206.98.168.162
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Yue-hong Zheng wrote:
  13. > Can any body give me any examples to show non-pure
  14. > virtual function does make sense?
  15.  
  16. This example could be used in a windowing system
  17. to make a hidden window.  Ms-Windows programmers
  18. will recognize this as a Modalless dialog box
  19. courtesy of Jeffrey M. Richter from "Windows 3.1:
  20. A Developer's Guide." (ie, It's a practical example.)
  21.  
  22. struct win {
  23.    void show() { ::show(w); }
  24.    int w;
  25. };
  26.  
  27. // most derived types use win::show()
  28. // for example:
  29. struct button : public win {
  30.    // uses win::show to display the window
  31.    // other button code also goes here
  32. };
  33.  
  34. struct hack_to_make_hidden_window : public win {
  35.    void show() { if (enabled) win::show(); } 
  36.    int  enabled;
  37. };
  38.  
  39.  
  40.